package com.designCreator.utils
{
	import mx.controls.Alert;

	public final class commonFunc
	{
		public static function search(whatToSearch:*,whereToSearch:*,propToSearch:String=""):int
		{
			if(whatToSearch == null || whereToSearch == null)
				return -1;
			var index:int = -1 ;
			
			var arrLength:int = 0;
			
			if(whereToSearch is Array)
			{
				arrLength =  whereToSearch.length ;
			}
			
			if(propToSearch.length>0)
			{
				var count:int = 0;
				while(count < whereToSearch.length)
				{
					if(whereToSearch[count][propToSearch] == whatToSearch)
					{
						index = count ;
						break;
					}
					count ++;
				}
				
			}else
			{
				var count1:int = 0;
				while(count1 < whereToSearch.length)
				{
					if(whereToSearch[count1] == whatToSearch)
					{
						index = count1 ;
						break;
					}
					count1 ++;
				}
				
			}
			
			return index ;
		}	
		
		/**This method search whatToSearch in xmllist whereToSearch 
		 * by using property propToSearch
		 * propToSearch.length is always greater than 0*/
		public static function searchInXmlList(whatToSearch:*,whereToSearch:XMLList,propToSearch:String=""):int
		{
			if(whatToSearch == null || whereToSearch == null)
				return -1;
			var index:int = -1 ;
			
			var count:int = 0;
			while(count < whereToSearch.length())
			{
				if(whereToSearch[count][propToSearch] == whatToSearch)
				{
					index = count ;
					break;
				}
				count ++;
			}
			return index ;
		}	
	}
}